<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>正在启动微信扫码...</title>
    <script src="./jquery.min.js"></script>
    <script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
</head>

<body>
    <script>
        window.sessionStorage.removeItem("qrCode");
        try {
            $.ajax({
                type: 'POST',
                url: '/wechat/getWechatJSSDKConfig.action',
                data: { requestUrl: "http://csfy.bgi.com/wechat/assets/qrcode.html" },
                success: function (data) {
                    if (data && data.success && data.object) {
                        console.dir(data.object);
                        var appid = data.object.appId;
                        var timestamp = data.object.timestamp;
                        var nonceStr = data.object.nonceStr;
                        var signature = data.object.signature;
                        console.log("appid = " + appid + ",timestamp=" + timestamp + ",nonceStr=" + nonceStr + ",signature=" + signature);
                        wx.config({
                            debug: false,
                            appId: appid,
                            timestamp: timestamp,
                            nonceStr: nonceStr,
                            signature: signature,
                            jsApiList: ['scanQRCode']
                        });

                        wx.ready(function () {
                            wx.scanQRCode({
                                needResult: 1,
                                desc: 'scanQRCode desc',
                                success: function (res) {
                                    try {
                                        if (res.errMsg === 'scanQRCode:ok') {
                                            var qrCode = res.resultStr;
                                            if(qrCode.indexOf(",") != -1) {
                                                qrCode = qrCode.substring(qrCode.indexOf(",") + 1, qrCode.length);
                                            }
                                            window.sessionStorage.setItem("qrCode", qrCode);
                                        }
                                    } catch (e) {
                                    }
                                    window.history.back();
                                },
                                cancel: function (res) {
                                    window.history.back();
                                },
                                fail: function (res) {
                                    window.history.back();
                                }
                            });
                        });
                    } else {
                        window.history.back();
                    }
                },
                error: function (e) {
                    window.history.back();
                },
                dataType: 'json'
            });
        } catch (e) {
            window.history.back();
        }
    </script>
</body>

</html>